package com.example.design.bilibili.factory.simpleFactory;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class OrderPizza {

    SimpleFactory simpleFactory;

    Pizza pizza = null;

    public OrderPizza(SimpleFactory simpleFactory) {
        setSimpleFactory(simpleFactory);
    }

    public void setSimpleFactory(SimpleFactory simpleFactory) {
        String orderType = "";//用户输入的

        this.simpleFactory = simpleFactory;//设置简单工厂对象
        do{
            orderType = getType();
            this.pizza = simpleFactory.createPizza(orderType);
            //输入Pizza
            if(pizza != null){//订购成功
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else{
                System.out.println("订购失败");
                break;
            }
        }while (true);
    }

    //写一个方法，可以获取客户希望订购的类型
    public String getType(){
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza 种类");
            String str = br.readLine();
            return str;
        }catch (Exception e){
            e.printStackTrace();
            return "";
        }
    }
}
